package com.zmn.plat.admin.controller.service.category;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.plat.common.dictionary.ProductDict;
import com.zmn.plat.model.entity.service.category.ItemCategory;
import com.zmn.plat.model.entity.service.category.ItemCategoryQuery;

/**
 * 故障分类表
 *
 * @author tanbiao
 * @since 2019-11-21 18:56:50
 */
@RequestMapping("/service/category/")
@Controller
public class ItemCategoryListController extends ItemCategoryBaseController {

    /**
     * 列表
     *
     * @param query
     * @author tanbiao
     * @since 2019-11-21 18:56:50
     */
    @RequestMapping("list")
    @RequiresPermissions("/service/category/list.action")
    public ModelAndView list(@ModelAttribute ItemCategoryQuery query) {

        List<ItemCategory> items = faultCategoryService.listPageByQuery(query);

        ModelAndView mav = new ModelAndView("service/category/list");
        mav.addObject("items", items);
        mav.addObject("vo", query);
        mav.addObject("statuses", GlobalDict.getStatusList(false));
        mav.addObject("bizTypeList", ProductDict.listBizType());
        return mav;
    }

    /**
     * 详情：如果是新增的情况下返回新对象，并将排序最大值赋予
     *
     * @param categId
     * @author tanbiao
     * @since 2019-11-21 18:56:50
     */
    @RequestMapping("detail")
    @RequiresPermissions("/service/category/detail.action")
    public ModelAndView detail(@RequestParam(value = "categId", defaultValue = "0") Integer categId) {
        ItemCategory faultCategory = faultCategoryBService.findByKey(categId);
        ModelAndView mav = new ModelAndView("service/category/detail");
        mav.addObject("faultCategory", faultCategory);
        return mav;
    }

}
